<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.css" rel="stylesheet">
</head>
<body>
<div id="app">
  <div class="wrap" style="max-width:600px;margin:20px auto">
    <div class="row">
      <div class="col-md-10 col-sm-10">
        <input type="text" v-model="inputText" class="form-control">
      </div>
      <div class="col-md-2 col-sm-2">
        <button @click="addTodo" class="btn btn-primary">增加</button>
      </div>
    </div>
    <ul class="list-group" style="margin-top: 20px;">
      <li v-if="arr.length===0" class="list-group-item" style="text-align: center;color: #999;">暂无代办事项</li>
      <li
        v-for="(item,index) in arr"
        class="list-group-item">
        {{item.add}}
        <button @click="deladd(index)" class="btn btn-danger btn-xs" style="float: right;">删除</button>
        <button @click="addaa(index)" :disabled="item.adds" class="btn btn-success btn-xs" style="float: right;margin-right: 10px;">{{item.adds?'已完成':'点击完成'}}</button>
      </li>
    </ul>
  </div>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.js"></script>
<script>
  const vm = new Vue({
    el: '#app',
    data: {
      inputText: '',
      arr:[
        {
          add: '打豆豆',
          adds: false
        },
        {
          add: '打篮球',
          adds: true
        }
      ]
    },
    methods: {
      deladd(index){
        if(confirm('你确定要删除吗？')){
          this.arr.splice(index,1)
        }
      },
      addTodo(){
        if(this.inputText.trim() === ""){
          return
        }
        this.arr.push({
          add: this.inputText,
          adds: false
        })
        this.inputText = ""
      },
      addaa(index){
        this.arr[index].adds= true
      }
    }
  })
</script>

</html>